#if !defined(BLAST_RESULTS_H)
#define BLAST_RESULTS_H

#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>

namespace AlignLib{
class Alignata;
}
namespace bcpp_align
{
							
struct t_gap
{
	unsigned beg;
	unsigned len;
	t_gap(unsigned b, unsigned l):beg(b), len(l){}
};

struct t_align_results
{
	t_align_results()
							: e__value(100.0), bitscore(0.0),
							  align_beg(0), align_len(0), total_len(0),
								len1(0), len2(0), aligned_residues(0), percent_id(0.0){}
	double					e__value;
	double					bitscore;
	std::vector<t_gap>		gaps1;
	std::vector<t_gap>		gaps2;
	unsigned 				align_beg;
	unsigned 				align_len;
	unsigned 				total_len;
	unsigned	 			len1;
	unsigned	 			len2;
	unsigned				aligned_residues;
	double					percent_id;
	void					swap_subject_query()
							{
								std::swap(gaps1,  gaps2);
								std::swap(len1,  len2);
							}
	std::string				error_message;
	static std::string		get_sql_column_names();
	static std::string		column_names();
	static std::string		column_name_underscores();
	static std::string		column_names2();
	static std::string		column_name_underscores2();
};


struct t_debug_align_results
{
	const t_align_results& blast_results;
	t_debug_align_results (const t_align_results& blast_results_)
	:blast_results(blast_results_){}
};


//________________________________________________________________________________________

//		expand_gaps

//________________________________________________________________________________________
void insert_gaps_into_sequence_pair(	const t_align_results&	pair_data,
										std::string&			sequence1,
										std::string&			sequence2,
										bool					cdna,
										std::string&			acc1,
										std::string&			acc2);
bool expand_gaps_prot(const std::vector<t_gap>& gaps, std::string& prot);

bool expand_gaps_cdna(const std::vector<t_gap>& gaps, std::string& cdna);
std::string gap_array_to_str(const std::vector<t_gap>& gaps);
bool gap_str_to_array(const std::string& gaps_str, std::vector<t_gap>& gaps);
void get_gaps_from_cdna_sequence(const std::string& sequence, std::vector<t_gap>& gaps, char gap_char = '-');
void get_gaps_from_prot_sequence(const std::string& sequence, std::vector<t_gap>& gaps, char gap_char = '-');
void get_align_results_from_cdna_sequence_pairs(t_align_results& align_result,
													const std::string& seq1,
													const std::string& seq2);
void get_align_results_from_prot_sequence_pairs(t_align_results& align_result,
													const std::string& seq1,
													const std::string& seq2);

// call this to prepare sequence strings before passing to do_bl2seq
//std::string bl_retrieve_string_from_prepared_sequence(const std::string& str);
void bl_prepare_sequence_str(std::string& str);
// forward declaration
//class t_collect_sequences;
//void bl_prepare_all_sequences(BioCPP::t_collect_sequences& seq_db);
std::istream& operator >> (std::istream& istrm, t_align_results& results);
std::ostream& operator << (std::ostream& ostrm, const t_align_results& results);
std::ostream& operator << (std::ostream& ostrm, const t_debug_align_results& debug);
void alignata_to_blast_results( const AlignLib::Alignata& src, 
								const std::string& seq1,
								const std::string& seq2,
								t_align_results& res);
}
#endif
